package com.ourteam.product.model.api;

import com.ourteam.product.model.domain.ProductModelObjectRelateBean;
import com.ourteam.product.model.domain.ProductModelPropertyRelateBean;
import com.ourteam.product.model.service.IProductModelService;
import com.ourteam.product.model.service.ProductModelServiceFactory;

public class ProductModelObjectRelateHelper{

	static final IProductModelService PRODUCT_MODEL_SERVICE = ProductModelServiceFactory.getProductModelService();

	private ProductModelObjectRelateBean modelObjectRelateBean;

	public ProductModelObjectRelateHelper(
			ProductModelObjectRelateBean modelObjectRelateBean) {
		super();
		this.modelObjectRelateBean = modelObjectRelateBean;
	}

	public ProductModelObjectHelper getModelObject() throws Exception {
		return ProductModelObjectHelper.getInstance(this.modelObjectRelateBean
				.getObjectId());
	}

	public ProductModelObjectHelper getRelatedModelObject() throws Exception {
		return ProductModelObjectHelper.getInstance(this.modelObjectRelateBean
				.getRelatedObjectId());
	}

	public String getRelateType() {
		return this.modelObjectRelateBean.getRelatedType();
	}

	public String getRelateName() {
		return this.modelObjectRelateBean.getRelateName();
	}

	public String getRelateConfig() {
		return this.modelObjectRelateBean.getRelatedConfig();
	}

	public ProductModelPropertyRelateHelper[] getModelPropertyRelations()
			throws Exception {
		ProductModelPropertyRelateBean[] propertyRelateBeans = PRODUCT_MODEL_SERVICE
				.getProductModelPropertyRelates(this.modelObjectRelateBean
						.getId());

		ProductModelPropertyRelateHelper[] relateHelpers = new ProductModelPropertyRelateHelper[propertyRelateBeans.length];

		for (int i = 0; i < relateHelpers.length; i++) {
			relateHelpers[i] = new ProductModelPropertyRelateHelper(
					propertyRelateBeans[i]);
		}

		return relateHelpers;
	}
}
